<template>
  <div class="prop-select-dialog">
    <el-dialog :title="propSelectDialog.title" :visible.sync="propSelectDialog.show" :close-on-click-modal="false" width="500px" >
      <el-scrollbar style="height: 300px">
        <el-tree ref="propSelectTree" :data="propTree" :props="defaultPropTreeProps" :expand-on-click-node="false" node-key="Id" default-expand-all show-checkbox highlight-current />
      </el-scrollbar>
      <div slot="footer">
        <el-button type="primary" @click="onConfirmPropIdList">Confirm</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: 'PropSelectDialog',
  props: {
    value: {
      type: Object,
      default() {
        return {}
      }
    },
    propTree: {
      type: Array,
      default() {
        return []
      }
    }
  },
  data() {
    return {
      propSelectDialog: {},
      defaultPropTreeProps: {
        children: 'ChildrenList',
        label: 'Title'
      }
    }
  },
  watch: {
    value: {
      handler(val) {
        this.propSelectDialog = val
      },
      deep: true,
      immediate: true
    },
    propSelectDialog: {
      handler(val) {
        this.$emit('input', val)
        this.$emit('on-change', val)
      },
      deep: true
    }
  },
  methods: {
    onConfirmPropIdList() {
      this.$set(this.propSelectDialog.form, 'PropIdList', this.$refs.propSelectTree.getCheckedKeys())
      this.$set(this.propSelectDialog, 'show', false)
    }
  }
}
</script>

<style scoped>

</style>
